package com.bobo.servicepay.controller;

import com.bobo.servicepay.dao.TbPayDao;
import com.bobo.servicepay.entry.TbPay;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.codingapi.txlcn.tc.annotation.TccTransaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Date;

/**
 * @author bobo
 * @date 2021-04-07
 */
@RestController
public class PayController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private TbPayDao tbPayDao;

    @GetMapping("/pay")
    @LcnTransaction
    public String pay() {
        // 插入支付流水
        TbPay tbPay = new TbPay();
        tbPay.setId(1);
        tbPay.setPayTime(new Date());
        tbPayDao.insert(tbPay);

        // 调用service-order
        String forObject = restTemplate.getForObject("http://service-order/order", String.class);
        System.out.println("order:" + forObject);

        // 调用service-pay
        String result = restTemplate.getForObject("http://service-ship/ship", String.class);
        System.out.println("ship:" + result);
        return "success";

    }
}
